#!/bin/sh

# Save Gargoyle version to UCI
gargoyle_version=$(cat /www/data/gargoyle_version.txt)
uci set gargoyle.global.version="$gargoyle_version"

# Set hostname to Gargoyle
uci set system.@system[0].hostname="Home_Internet_cafe" 2>/dev/null
echo "Home_Internet_cafe" > /proc/sys/kernel/hostname   2>/dev/null

# disable logging for cron -- it tends to clutter up logs, and it logs all jobs at "error" level, which is wrong
uci set system.@system[0].cronloglevel=9

# Allow resolution of NameCoin and OpenNIC domains by default
uci add_list dhcp.@dnsmasq[0].server="/.bit/178.32.31.41"
uci add_list dhcp.@dnsmasq[0].server="/.bit/78.47.86.43"
for tld in "/.glue/" "/.parody/" "/.dyn/" "/.bbs/" "/.free/" "/.fur/" "/.geek/" "/.gopher/" "/.indy/" "/.ing/" "/.null/" "/.oss/" "/.micro/" ; do
	for ip in "66.244.95.20" "95.211.32.162" "95.142.171.235" ; do
		uci add_list dhcp.@dnsmasq[0].server="$tld$ip"
	done
done

# Rules: By default all users are only allow to access the router interface

uci set firewall.rule_1="restriction_rule" 2>/dev/null
uci set firewall.rule_1.is_ingress="0" 2>/dev/null
uci set firewall.rule_1.description="CodeIdentifyRule" 2>/dev/null
uci set firewall.rule_1.not_remote_addr="192.168.1.1" 2>/dev/null
uci set firewall.rule_1.proto="tcp" 2>/dev/null
uci set firewall.rule_1.enabled="1" 2>/dev/null




#save changes to uci
uci commit



# remove init scripts of things that should not be active by default
/etc/init.d/miniupnpd disable       2>/dev/null
/etc/init.d/qos_gargoyle disable    2>/dev/null
/etc/init.d/webmon_gargoyle disable 2>/dev/null

# ensure ntpclient is active
chmod 755 /etc/hotplug.d/iface/20-ntpclient 2>/dev/null

#make sure date isn't set to 1970, which may cause issues with timezones that cause time to go back before unix epoch,  set to Jan 1st 2001
curdate=$(date -u +%s)
if [ $curdate -lt 978307200 ] ; then
	date -u -s 2001.01.01-00:00:01
	mkdir /data
	echo "2001.01.01-00:00:01" >/data/time_backup
fi




#set sysupgrade.conf
cat << EOF >/etc/sysupgrade.conf
/etc/passwd
/etc/config
/etc/rc.d
/etc/TZ
/etc/firewall.user
/etc/ethers
/etc/hosts
/etc/webmon_ips
/etc/crontabs
/etc/dropbear
/tmp/data
/usr/data
/etc/tor
EOF




#create original backup
sh /usr/lib/gargoyle/create_backup.sh
mkdir /etc/original_backup
cp /tmp/backup/backup.tar.gz /etc/original_backup/backup.tar.gz


